function displayHideUI(obj)
{
	 $(obj).children('.a').css("display","none");
}
function displayShowUI(obj)
{
	  $(obj).children('.a').css("display","block");
}

function  checked(obj){
	if(obj.getAttribute('ischecked')==1){
		obj.setAttribute('ischecked','0');
		displayHideUI(obj);
		calculation(obj);
		console.log(obj.getAttribute('ischecked'));			
	}else{
		obj.setAttribute('ischecked','1');
		
		displayShowUI(obj);
		calculation(obj);
		console.log(obj.getAttribute('ischecked'));
	}

}
function calculation(obj){
	var couponsumobj= document.getElementById('couponsum');
	var sum;
	//var activeSum;
	if(obj.getAttribute('ischecked')==1){
		sum = parseFloat(couponsumobj.innerHTML)+parseFloat(obj.getAttribute('CouponValue'));
		console.log(sum);
		couponsumobj.innerHTML=sum;
		
		//activeSum = parseFloat($('#activeAmount').val())+parseFloat(obj.getAttribute('ActiveAmount'));
		//console.log(activeSum);
		//$('#activeAmount').val(activeSum);
		
	}else{
		sum = parseFloat(couponsumobj.innerHTML)-parseFloat(obj.getAttribute('CouponValue'));
		console.log(sum);
		couponsumobj.innerHTML=sum;
		
		//activeSum = parseFloat($('#activeAmount').val())-parseFloat(obj.getAttribute('ActiveAmount'));
		//console.log(activeSum);
		//$('#activeAmount').val(activeSum);
		
	}	
}

function text(json){  
	var sum=0.0;
	var json = json?json:{"coupon":[{"couponId":"59AF1928-0FB9-4A8A-B481-50A9F0D73D53","CouponValue":"20.00"}]};   
	json = eval(json.coupon)  
	for(var i=0; i<json.length; i++)  
	{  
		if($("div[couponId="+json[i].couponId+"]").length>0){
			$("div[couponId="+json[i].couponId+"]").attr('ischecked','1');
			$("div[couponId="+json[i].couponId+"]").attr('class','check');
			sum += parseFloat(json[i].CouponValue);
		}
		
	} 
	document.getElementById('couponsum').innerHTML = sum;	
}
	
function dataParams(params){
        this.params = params;
        /*
		this.stActiveAmount = ActiveAmount;
		this.stCouponValueSum = CouponValueSum;
		this.stCouponIdList = CouponIdList;
        */
}
	
function bridgeData(messageType,params){
		this.messageType = messageType;
//		this.params = new dataParams(params);
		this.params = params;
}
	
window.onerror = function(err) {
	console.log('window.onerror: ' + err);
}
	
	
	
	

$(document).ready(function(){
	var buttons = $("input[id^='ret_']");
	if(buttons.length>0){
		$.each(buttons,function(n,value){
			$(value).click(function(){
//				var ActiveAmount = parseFloat($(value).attr('ActiveAmount'));
//				var CouponValueSum = parseFloat($(value).attr('CouponValue'));
				var params = $(this).attr('params');
				var messageType = $(this).attr('messageType');
//				var dataObj = new bridgeData('selectCoupon',ActiveAmount,CouponValueSum,CouponIdList);
				var dataObj = new bridgeData(messageType ,params);
				var data = JSON.stringify(dataObj);

//		            var message = { data:data };
                    //alert(data);
//		            window.ideliver.messageFromJS(JSON.stringify(data));			
				window.ideliver.messageFromJS(data);			
			});
		});
	}
	var buttons = $("input[id^='left']");
	if(buttons.length>0){
		$.each(buttons,function(n,value){
			$(value).change(function(){
				alert($(value).val());
				if(value != 0) return;
//					var ActiveAmount = parseFloat($(value).attr('ActiveAmount'));
//					var CouponValueSum = parseFloat($(value).attr('CouponValue'));
				var params = $(this).attr('params');
				var messageType = $(this).attr('messageType');
//					var dataObj = new bridgeData('selectCoupon',ActiveAmount,CouponValueSum,CouponIdList);
				var dataObj = new bridgeData(messageType ,params);
				var data = JSON.stringify(dataObj);

//		            var message = { data:data };
                    //alert(data);
//		            window.ideliver.messageFromJS(JSON.stringify(data));			
				window.ideliver.messageFromJS(data);			
			});
		});
	}
});
